#include "StdAfx.h"
#include "my_session_event_handler.h"
#include "my_session_mgr.h"

using namespace utility::network;

void CSessionEventHandler::on_established()
{
    cout<<"connection established: remote ip is " << m_pSession->get_remote_ip_as_string()
        <<", port is "<< m_pSession->get_remote_port()<< endl;
}

void CSessionEventHandler::on_disconnected()
{
    cout<< "disconnected from remote ip "<< m_pSession->get_remote_ip_as_string() << endl;
    CSessionMgr::Instance().ReleaseEventHandler(this);
}

void CSessionEventHandler::on_error(int32 error_code, const char * error_message)
{
    cout<< "error occured with error code " << error_code
        << "(" << error_message << ")" << endl;
}

void CSessionEventHandler::on_receive(const char *message, uint32 message_length)
{
    cout<< "receive message from ip (" << m_pSession->get_remote_ip() 
        << "), and length is "<< message_length 
        << ". message is " << string(message, message_length)
        << endl;
}

void CSessionEventHandler::SetSession(const session * pSession)
{
    m_pSession = const_cast<session*>(pSession);
}
